package cn.smbms.convertor;

import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateConvertor implements Converter<String, Date> {

    private String dateFormat;

    public String getDateFormat() {
        return dateFormat;
    }

    public void setDateFormat(String dateFormat) {
        this.dateFormat = dateFormat;
    }

    @Override
    public Date convert(String s) {
        try {
            return new SimpleDateFormat(dateFormat).parse(s);
        } catch (ParseException e) {
            System.out.println("日期转换异常");
            e.printStackTrace();
        }
        return null;
    }
}
